﻿#region Includes
using System;
#endregion

namespace GingerGL.Graphics.Models.MD3
{
    //------------------------------------------------------------//
    /// <summary>
    /// Component of the MD3 Model
    /// </summary>
    public class Component : IDisposable
    {
        //--------------------------------------------------------//
        #region Variables
        /// <summary>
        /// Name of Component
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// Component Type
        /// </summary>
        public ComponentType PartType { get; set; }
        /// <summary>
        /// Source File
        /// </summary>
        public string FileName { get; set; }
        /// <summary>
        /// Frame Data
        /// </summary>
        public FrameInfo[] Frames { get; set; }
        /// <summary>
        /// Tag Data
        /// </summary>
        public Tag[] Tags { get; set; }
        /// <summary>
        /// Mesh Data
        /// </summary>
        public AnimatedMesh[] Meshes { get; set; }
        #endregion
        //--------------------------------------------------------//
        #region Constructors
        /// <summary>
        /// Initializes a new instance of object
        /// </summary>
        public Component(string name)
        {
            Name = name;
            PartType = ComponentType.Other;
            FileName = String.Empty;
            Frames = null;
            Tags = null;
            Meshes = null;
        }
        #endregion
        //--------------------------------------------------------//
        #region Methods
        /// <summary>
        /// Finds Tag
        /// </summary>
        /// <param name="name">Name of the Tag</param>
        /// <returns>Blank Mesh is returned if not found</returns>
        public Tag FindTag(string name)
        {
            foreach (Tag tag in Tags) { if (tag.Name == name) return tag; }
            return null;
        }
        /// <summary>
        /// Finds Mesh
        /// </summary>
        /// <param name="name">Name of Mesh</param>
        /// <returns>Blank Mesh is returned if not found</returns>
        public AnimatedMesh FindMesh(string name)
        {
            foreach (AnimatedMesh mesh in Meshes) { if (mesh.Name == name) return mesh; }
            return null;
        }
        /// <summary>
        /// Clean up garbage
        /// </summary>
        public void Dispose()
        {
            foreach (AnimatedMesh m in this.Meshes)
                m.Dispose();
            this.Tags = null;
            this.Frames = null;
        }
        #endregion
        //--------------------------------------------------------//
    }
    //------------------------------------------------------------//
}
